import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateFoodDto } from './dto/create-food.dto';
import { UpdateFoodDto } from './dto/update-food.dto';
import { Repository } from 'typeorm';
import { Food } from './entities/food.entity';
import { InjectRepository } from '@nestjs/typeorm';
@Injectable()
export class FoodsService {

  constructor( @InjectRepository(Food) private readonly footsResponsitory:Repository<Food>){}

  create(createFoodDto: CreateFoodDto) {
    return 'This action adds a new food';
  }

  findAll() {
    return `This action returns all foods`;
  }

  findOne(params) {
    if (!params.id) {
      throw new HttpException(
        '缺少必须参数id',
        HttpStatus.BAD_REQUEST,
      )
    }
    return this.footsResponsitory.findOneBy({ footid:params.id })
  }

  update(id: number, updateFoodDto: UpdateFoodDto) {
    return `This action updates a #${id} food`;
  }

  remove(id: number) {
    return `This action removes a #${id} food`;
  }
}
